# 图像归一化是将图像中的像素值缩放到特定范围的过程。
# 这样做通常是为了提高图像处理算法的性能，因为许多算法在像素值在一定范围内时工作得更好。

# Import the necessary Libraries
import cv2
import numpy as np
import matplotlib.pyplot as plt

# Load the image
image = cv2.imread('cat_dog.jpg')

# Convert BGR image to RGB
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Split the image into channels
r, g, b = cv2.split(image_rgb)

cv2.imshow('window1', r)
cv2.imshow('window2', g)
cv2.imshow('window3', b)

# Normalization parameter
min_value = 0
max_value = 1
norm_type = cv2.NORM_MINMAX

# Normalize each channel
r_normalized = cv2.normalize(r.astype('float'), None, min_value, max_value, norm_type)
b_normalized = cv2.normalize(b.astype('float'), None, min_value, max_value, norm_type)
g_normalized = cv2.normalize(g.astype('float'), None, min_value, max_value, norm_type)

# Merge the normalized channels back into an image
normalized_image = cv2.merge((r_normalized, g_normalized, b_normalized))
# Normalized image
print(normalized_image[:,:,0])

plt.imshow(normalized_image)
plt.xticks([])
plt.yticks([])
plt.title('Normalized Image')
plt.show()
